﻿//===================================================================
// 项目名称  
// 模块名称：进货单管理
// 类    名：
//===================================================================
// 历史：
// Date        Modified_By  Reason      Description 
// 2009/11/02    刘亮        创建         废烟支管理

//===================================================================
//  Copyright (c) 2009-2010   
//===================================================================

var form1 = {
    type  : "form", 
    name  : "search",   
    title : "查询条件",
    
    isSearch : true,            
    items : [
            
           
            {
                type:"calendar",
                title:"开始日期",
                // url:"../data/MoistureOvenCheckView5.txt" ,
                root:"dataset.simplecombobox"
            },
			 {
                type:"calendar",
                title:"结束日期",
                // url:"../data/MoistureOvenCheckView5.txt" ,
                root:"dataset.simplecombobox"
            },
			{ 
	        type: "combox",
	        title: "资金形式",
	        dataIndex: 'equModelId',
	        root: "dataset.dictionary",
	        fieldText: "name",
	        fieldValue: "id",
	        url: "../../dictionary.do?method=findDictionary&filter_EQS_sysFlag=1&filter_EQS_type.id=67021AF2F9984FDD918EB4521CA3087C"             
      },{ 	
	    	type:"treeChoice",   
	    	title:"生产点",
	    	dataIndex:'factory',
  			root:"dataset.dictionary",
  			fieldValue:"id",
  			fieldText:"name",
  			treeConfig : {
	            url      : "../../dictionary.do?method=findTree&filter_EQS_sysFlag=1&filter_EQS_id=FF85E8FB01704DA0AFC9825D9BA6A832",
	            resource : 'dic',
	            width: 400,
	            height: 400,
	            isParent:false,
	            treeType:"checked",
	            treeTitle: "生产点选择"
	        }} 
    ],

   layoutConfig : 
    {
        columns : 4
    },
    layout : 
	[
		{
		items:
			[
				{'name':'开始日期'}, 
				{'name':'结束日期'}, 
				{'name':'资金形式'}  
			]
		}
    ]
};

//=======================================================================================
//定义一个静态列表表单对象 grid1
//=======================================================================================
var grid1 = {
    "name"      : "grid1",
    "type"      : "grid",
    "title"     : "进货单管理",
    colCheckbox : true,
    pageSize:12,

    "tbar"      : [
        {text: '新增'}, '-',
        {text: '删除'}
    ],
    "bindRelation"   : {
        "root"  :"dataset.billVo",
         id    : "id",
         
        "col"   :[
			{"header": "事务主键","width": 0,"dataIndex": "transactionId",hidden:true},        
            {"header":"进货日期",  "width":100, "align":"left",  "dataIndex":"billDate"},    
            {"header":"单据类型",  "width":100, "align":"left",  "dataIndex":"billTypeName"},
            {"header":"资金形式",  "width":100, "align":"left",  "dataIndex":"otherDic1Name"},     
            {"header":"经手人",    "width":100, "align":"left",  "dataIndex":"operator"},     
            {"header":"备注",      "width":100, "align":"left",  "dataIndex":"remark"},
            {"header":"修改",      "actionCol" :true },    
            {"header":"查看",      "actionCol" :true }
        ]
        
    }
};
var grid2 = {
    "name"      : "grid2",
    "type"      : "grid",
    "title"     : "进货单明细",
    haveCheckCol: true,
        "bbar":false,
       "bindRelation"   : {
        "root"  :"dataset.billDetailVo",
        id   : "id",
        "col"   :[     
            {"header":"产品名称",  "width":100, "align":"left",  "dataIndex":"materielName"},      
            {"header":"数量",      "width":100, "align":"left",  "dataIndex":"amount"}
        ]
        
    }
};

var page1 = new Sail.page({
    id : "page_001",
    haveNavi:true,
        localNaviText : "您的位置：仓库管理>进货单管理",
    frames : {
        name   : "RollStandardList",
        title  : "标题",
        autoLoad : false,
        items  : [form1,grid1,grid2],
        layoutConfig: {
            columns: 2,
            width: [0.8, 0.2]
        },
        layout: [
        {
            items: [{
                name: 'search',
                colspan:2
            }]
        },
        {
            items: [
            {
                name: 'grid1'
            },
            {
                name: 'grid2'
            }]
        }       
        
        ],
        

        
        bindEvent2Items : function(){
     
        	$('search').addButtonHandler('查询',function(){
        		queryData();
             },$('search'));
        	
           $('grid1').getButton('新增').on('click',function(){
                Sail.open("jinghoudanUpdate.html","add",{},800,600);
           });
           
            $('grid1').addAction('修改',function(pid,row,record,value){
                var flag = Sail.open("jinghoudanUpdate.html","update",{"id":pid},1000,800);
                flag && queryData();
            });           
     
            $('grid1').getButton('删除').on('click',function(){
              if (confirm("确认要删除所选择的数据吗？")) {
                  var ids = $('grid1').getSelections('id').join(':');
                  alert(ids);
                  if (ids==''){
                    return;
                  }
                  Sail.postData('../../purchase.do?method=delete', {
                      'ids': ids
                  },
                  function(flag, getData) {
                      if (flag == "true") {
                          Ext.Msg.alert("提示", "操作成功!");
                          $('grid1').load();
                      } else {
                          Ext.Msg.alert("警告", getData.dataset.response.content);
                      }
                  });
              }
          });
            
        $('grid1').on('afterload', function () {
            $('grid1').selectFirstRow();
            var id = $('grid1').getSelections('id');
            if (id == "") {
                $('grid2').removeAll();
            }
        });
        $('grid1').on('rowclick', function (id, row, record) {
        		if (id == "") {
        			return;
        		}
        		var transactionId=record.get("transactionId");
        		if (transactionId == "") {
        			return;
        		}
            $('grid2').load("../../purchase.do?method=listDetail&lastTransactionId="+transactionId);
        });

       }       
    },
    afterRun : function(){
        queryData();
    }
});

page1.run();

function queryData() {
	var zjxs = $('资金形式').getValue();
	$('grid1').load("../../purchase.do?method=list&filter_EQS_sysFlag=1&filter_EQS_billType.id=C7403048BF6C430D8DE9F737E9690DDB&filter_EQS_otherDic1.id="+zjxs);
}